package com.bjc.principle.singleton.type7;

/**
 * @program: DesignPattern
 * @description:
 * @author: bjc
 * @create: 2020-12-13 20:55
 */
public class SingletonTest07 {
    public static volatile char STR = 'a';
    public static void main(String[] args) {

//        Singleton instance1 = Singleton.INSTANCE;
//        Singleton instance2 = Singleton.INSTANCE;
//        System.out.println(instance1==instance2);
//        System.out.println(instance1.hashCode());
//        System.out.println(instance2.hashCode());
//        instance1.sayOk();
        int i = 1;
        while (true){
            while (STR=='a'){
                System.out.println(STR);
                STR = 'b';
            }
            while (STR=='b'){
                System.out.println(STR);
                STR = 'c';
            }
            while (STR=='c'){
                System.out.println(STR);
                STR = 'a';
            }
            i++;
            if (i==4){
                break;
            }
        }

//        new Thread(()->{
//           a();
//        }).start();
//        new Thread(()->{
//            b();
//        }).start();
//        new Thread(()->{
//            c();
//        }).start();
    }

    public static void a(){
        while (STR=='a'){
            System.out.println(STR);
            STR = 'b';
        }


    }

    public static void b(){
        while (STR=='b'){
            System.out.println(STR);
            STR = 'c';
        }
    }

    public static void c(){
        while (STR=='c'){
            System.out.println(STR);
            STR = 'a';
        }
    }
}

enum Singleton{
    INSTANCE;
    public void sayOk(){
        System.out.println("ok~");
    }
}
